<?php
    $plug = array();
    $log = array();
    $event = array();
    $runtime = array();
    
    function init(){
        debug("* Capsule Core Initialized *");
        
        create("init");
        create("runtime");
        create("libs");
        create("variables");
        create("load_sidebar");
        create("load_content");
        create("load_header");
        
        action("load_header","my_header_action");
        action("load_header","header_action_action2");

        runtime("action");
        runtime("event");
        runtime("filter");
        runtime("runtime");
        runtime("create");
        runtime("load");
        runtime("debug");
        
        
        
        load("ccfs");
        load("avatar24");
        
    }
    
    function debug($msg){
        global $log;
        
        array_push($log,$msg);
    }
    
    function event($spe,$function){
        global $event;
        
        if (is_array($event[$spe])){
             if (is_array($event[$spe]["event"])){
                array_push($event[$spe]["event"],$function);
                debug("* ATTACH EVENT - [ ".$spe." ]");
            }else{
                $event[$spe]["event"]=array();
                array_push($event[$spe]["event"],$function);
                debug("* ATTACH EVENT CREATED- [ ".$spe." ]");
            }
        }
    }
    
    function action($spe,$function){
        global $event;
        
        if (is_array($event[$spe])){
            if (is_array($event[$spe]["action"])){
                   array_push($event[$spe]["action"],$function);
                   debug("* ATTACH ACTION - [ ".$spe." ]");
            }else{
                $event[$spe]["action"]=array();
                array_push($event[$spe]["action"],$function);
                debug("* ATTACH ACTION CREATED- [ ".$spe." ]");
            }
        }
    }
    
    function runtime($function){
        global $runtime;
        
        if (is_array($runtime)){
                   array_push($runtime,$function);
                   debug("* ATTACH RUNTIME - [ ".$function." ]");
        }else{
            $event[$spe]["action"]=array();
            array_push($runtime,$function);
            debug("* ATTACH RUNTIME CREATED- [ ".$function." ]");
        }
    }
    
    function filter($spe,$function){
        global $event;
        
        if (is_array($event[$spe])){
             if (is_array($event[$spe]["filter"])){
                array_push($event[$spe]["filter"],$function);
                debug("* ATTACH FILTER - [ ".$spe." ]");
            }else{
                $event[$spe]["filter"]=array();
                array_push($event[$spe]["filter"],$function);
                debug("* ATTACH FILTER CREATED- [ ".$spe." ]");
            }
        }
    }
   
    
    function create($spe){
        global $event;
        
        $event[$spe]=array();
        debug("* CREATE - [ ".$spe." ]");
    }
    
    function load($path){
        global $plug;
        
        include_once ("plugins/".$path.".html");
        debug("* LOAD - ".$path.".html");
    }
    
    function showArray($array){
        if (is_array($array)){
            for ($i=0;$i<=count($array);$i++){
                echo '<span style="display:block;color:brown;font-size:11px;line-height:14px;font-family:verdana;">['.$i.'] '.$array[$i].'</span>';
            }
        }
    }
    
    
    init();
    
    
    
    showArray($log);
    
    
        
        $ltPlugins=scandir("/plugins");
        unset($ltPlugins['0'],$ltPlugins['1']);
        
        $tmBase=array();
        foreach ($ltPlugins as $nr => $value){
            $tmBase[$value]="*";
        }
        $ltPlugins=$tmBase;
    
    
    
    echo '<pre>';
        print_r($event);
        print_r($runtime);
        print_r($ltPlugins);
    echo '</pre>';
?>